/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Server;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Lucas
 */
public class Connection extends Thread{

    private Socket socket;
    private InputStreamReader inputStream;
    private OutputStreamWriter outputStream;
    private String name;

    public Connection(Socket sock, String naam){
        this.socket = sock;
        this.name = naam;
        try{
            inputStream = new InputStreamReader(socket.getInputStream());
            outputStream = new OutputStreamWriter(socket.getOutputStream());
        }
        catch(IOException e){
            System.err.println(e);
            System.exit(1);
        }
    }

    public String receive() throws IOException, ClassNotFoundException{
            return  Integer.toString(inputStream.read());
    }

    public void send(String o) throws IOException{
        outputStream.write(o);
    }
    public void setNaam(String naam){
        name = naam;
    }
    public String getNaam(){
        return name;
    }

    public void closeConnection(){
        try {
            socket.close();
        } catch (IOException ex) {
            Logger.getLogger(Connection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public boolean isConnected(){
        if(socket == null && inputStream == null && outputStream == null){
            return true;
        }
        else
            return false;
    }
}